<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" language="java" %>
<html>
<%@include file="../../common/include-header.jsp" %>

<body class="gray-bg">

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="role-form">
                <div class="select-list">
                    <ul>
                        <li>
                        年级:
                        <select required name="gradeId">
                            <option value="">请选择</option>
                            <c:forEach items="${grades}" var="grade">
                                <option value="${grade.id}">${grade.name}</option>
                            </c:forEach>
                        </select>
                        </li>
                        <li>
                        班级:
                        <select required name="classId" disabled>
                            <option value="">请选择</option>
                        </select>
                        </li>
                        <li>
                            <a id="ss" class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
            <hr/>
        </div>


        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true">

            </table>
        </div>
    </div>
</div>
<%@include file="../../common/include-footer.jsp" %>
<script th:inline="javascript">
    var prefix = "/examResult";
    $(function () {
        var options = {
            url: prefix + "/list2",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/update/{id}",
            removeUrl: prefix + "/remove/{id}",
            sortName: "asc",
            height: 500,
            modalName: "考试",
            columns: [
                {
                    field: 'stuNo',
                    title: '学生编号'
                },
                {
                    field: 'stuName',
                    title: '学生名称'
                },
                {
                    field: 'correctAmount',
                    title: '答对数'
                },
                {
                    field: 'amount',
                    title: '答题数'
                },
                {
                    field: 'accuracy',
                    title: '正确率'
                },
                {
                    field: 'score',
                    title: '分数'
                }
                ]
        };

            $.table.init(options);


        $('select[name=gradeId]').change(function () {
            var gradeId = $(this).val();
            $.ajax({
                url:"${pageContext.request.contextPath}/examResult/getClassByGradeId",    //请求的url地址
                dataType:"json",   //返回格式为json
                data:{"gradeId":gradeId},    //参数值
                type:"POST",   //请求方式
                success:function(data){
                    $('.examC').remove();
                    var classes = data;
                    for(var i=0;i<classes.length;i++){
                        var id = classes[i].id;
                        var name =classes[i].name;
                        // $("#subid").val([subid,subname]);
                        //给下拉框动态赋值
                        $("select[name=classId]").append("<option value='"+id+"' class='examC'>"+name+"</option>");
                    }
                    // alert($("#subid").val());
                }

            });
            $('select[name=classId]').attr("disabled",false);
        });

    });
</script>
</body>
</html>
